package ca.uvic.cs.cogz.mapping.ui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;

import ca.uvic.cs.cogz.util.BrowserLaunch;
import ca.uvic.cs.cogz.util.PropertiesManager;
import ca.uvic.cs.cogz.util.PropertiesManager.MappingVisualizationProperties;

public class SurveyRequestDialog extends JDialog {
	private static final long serialVersionUID = -2066890855402178042L;

	public SurveyRequestDialog(JFrame parent) {
		super(parent);

		setSize(400, 500);

		setResizable(false);
		setModal(true);
		setTitle("CogZ survey request");

		init();
	}

	private void init() {
		String request = "Thank you for using CogZ.  We are interested in recruiting users of CogZ to complete a short online survey "
				+ "to help us evaluate and improve CogZ's features.  The study is being conducted by Sean Falconer, a PhD student in the department "
				+ "of Computer Science at the University of Victoria.  You may contact Sean if you have questions.  Phone (250) 474-5778 " + "or e-mail seanf@uvic.ca\r\n\r\n"
				+ "We are very interested in having you participate.  Your participation is completely voluntary and you will not "
				+ "be identified by name in any work related to this study.  If you are interested in participating in this survey, "
				+ "please click the “Take me to the survey” button below.  Click “Ask me later” if you wish to defer this until a later time and click "
				+ "“Not interested” if you never want to participate.\r\n\r\n" + "Please contact Sean Falconer if you have further questions.\r\n\r\nThank you,";

		JEditorPane editorPane = new JEditorPane();
		editorPane.setEditable(false);
		editorPane.setFont(editorPane.getFont().deriveFont(12f));
		editorPane.setText(request);

		getContentPane().add(editorPane, BorderLayout.CENTER);

		JButton surveyButton = new JButton("Take me to the survey");
		JButton askMeLaterButton = new JButton("Ask me later");
		JButton neverAgainButton = new JButton("Not interested");

		surveyButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				BrowserLaunch.openURL("url to survey");
				PropertiesManager.getInstance().setProperty(MappingVisualizationProperties.NEVER_SHOW_SURVEY_AGAIN, "true");
				dispose();
			}
		});

		askMeLaterButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});

		neverAgainButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				PropertiesManager.getInstance().setProperty(MappingVisualizationProperties.NEVER_SHOW_SURVEY_AGAIN, "true");
				dispose();
			}
		});

		JPanel buttonPanel = new JPanel();
		buttonPanel.add(surveyButton);
		buttonPanel.add(askMeLaterButton);
		buttonPanel.add(neverAgainButton);

		JPanel tempPanel = new JPanel(new BorderLayout());
		tempPanel.add(buttonPanel, BorderLayout.EAST);

		getContentPane().add(tempPanel, BorderLayout.SOUTH);

		//PropertiesManager.getInstance().setProperty(MappingVisualizationProperties.NEVER_SHOW_SURVEY_AGAIN, neverShowAgain + "");
	}
}
